<template>
  <div>
    <Breadcrumb>
      <Breadcrumb-item href="/">
        <Icon type="ios-home-outline"></Icon> 配置管理
      </Breadcrumb-item>
      <Breadcrumb-item href="">
        <Icon type="social-buffer-outline"></Icon> 网站配置
      </Breadcrumb-item>
      <Breadcrumb-item>
        <Icon type="pound"></Icon> 推广配置
      </Breadcrumb-item>
    </Breadcrumb>
    <Form ref="formValidate" :label-width="120" style="margin-top: 20px;">
      <FormItem label="征信良好用户">
        <Row v-for="(item, index) in configInfo.good_credit_reporting" :style="index != 0 ? 'margin-top: 10px;' : ''">
          <Input v-model="item.title" placeholder="" style="width: 100px;" type="text"></Input> :
          <Input v-model="item.num" placeholder="" style="width: 80px;" type="number"></Input>人,之后新人第一单为征信良好赠送
          <Input v-model="item.green_scores" placeholder="" style="width: 80px;" type="number" placeholder="赠送积分"></Input>积分
        </Row>
      </FormItem>
      <FormItem label="黑户">
        <Row v-for="(item, index) in configInfo.black_households" :style="index != 0 ? 'margin-top: 10px;' : ''">
          <Input v-model="item.title" placeholder="" style="width: 100px;" type="text"></Input> :
          <Input v-model="item.num" placeholder="" style="width: 80px;" type="number"></Input>人
        </Row>
      </FormItem>
      <FormItem label="创业用户">
        <Row v-for="(item, index) in configInfo.entrepreneurship" :style="index != 0 ? 'margin-top: 10px;' : ''">
          <Input v-model="item.title" placeholder="" style="width: 100px;" type="text"></Input> :
          <Input v-model="item.num" placeholder="" style="width: 80px;" type="number"></Input>人
        </Row>
      </FormItem>
      <FormItem label="邀请注册送" class="item">
          <Input v-model="configInfo.direct_push" placeholder="邀请新人注册赠送积分" type='number' style="width: 300px;"></Input>
          <span style="margin-left: 10px;">绿色积分</span>
      </FormItem>
      <FormItem>
        <Button type="primary" @click="handleSubmit('formValidate')">保存</Button>
      </FormItem>
    </Form>
  </div>
</template>
<script>
  import config from "@/config";
  import {
    getToken
  } from "../../libs/util";
  const baseUrl = process.env.NODE_ENV === "development" ? config.baseUrl.dev : config.baseUrl.pro;
  export default {
    data() {
      return {
        //推广奖励配置
        visible: false,
        header: {
          token: getToken()
        },
        configInfo: {
          good_credit_reporting: [{
            title: "月供奖励",
            num: "0",
            green_scores: "0",
          }],
          black_households: [{
              title: "提车奖励",
              num: "0"
            },
            {
              title: "月供奖励",
              num: "0"
            },
          ],
          entrepreneurship: [{
              title: "提车奖励",
              num: "0"
            },
            {
              title: "月供奖励",
              num: "0"
            },
            {
              title: "其他奖励",
              num: "0"
            },
          ],
          direct_push:"0"
        }
      }
    },
    methods: {
      getConfigInfo() {
        this.$axios('/admin/config/getConfigInfo', {
          type: 5
        }).then(res => {
          if(res.good_credit_reporting != null){
            this.configInfo.good_credit_reporting = res.good_credit_reporting;
          }
          if(res.black_households != null){
            this.configInfo.black_households = res.black_households;
          }
          if(res.entrepreneurship != null){
            this.configInfo.entrepreneurship = res.entrepreneurship;
          }
          this.configInfo.direct_push = res.direct_push;
        });
      },
      handleSubmit() {
        let param = {
          ...this.configInfo
        };
        this.$axios('/admin/config/setConfig', param).then(res => {
          this.$Message.success('保存成功');
          this.getConfigInfo();
        })
      }
    },
    created() {
      this.getConfigInfo();
    },
  }
</script>
<style>
  .demo-upload-list {
    display: inline-block;
    width: 60px;
    height: 60px;
    text-align: center;
    line-height: 60px;
    border: 1px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    position: relative;
    box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
    margin-right: 4px;
  }

  .demo-upload-list img {
    width: 100%;
    height: 100%;
  }

  .demo-upload-list-cover {
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, .6);
  }

  .demo-upload-list:hover .demo-upload-list-cover {
    display: block;
  }

  .demo-upload-list-cover i {
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    margin: 0 2px;
  }
</style>
<style src="@wangeditor/editor/dist/css/style.css"></style>
